package com.liang.factorial;

import java.util.Arrays;

public class FactrialDemo3 {

    public static void main(String[] args) {

        System.out.println("斐波那契数组实现");
        int[] arr = new int[20];
        arr[0] = 1;
        arr[1] = 1;

        for (int i = 2; i < arr.length; i++) {
            arr[i] = arr[i - 1] + arr[i - 2];

        }
        System.out.println(Arrays.toString(arr));
        int result=0;
        for (int i = 0; i < arr.length; i++) {
            result += arr[i];
        }

        System.out.println(result);

        System.out.println("-----------------");

        System.out.println("斐波那契递归实现");

        //兔子的总数
        int mon = 20;

        int num = method(20);

        System.out.println(num);

    }

    public  static int method(int i) {
        if(i<=2){
            return 1;
        }else{
            return method(i - 1) + method(i - 2);
        }
    }


}
